package swu.commodity;

import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

public class CommodityService
{

    private CommodityRepo repo;
    public static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");

    public CommodityService(){}

    public List<Commodity> getAllCommodities() throws SQLException, ClassNotFoundException
    {
        return this.repo.getAll();
    }

    public void saveCommodity(Commodity commodity) throws SQLException
    {
        this.repo.save(commodity);
    }

    public void deleteCommodityById(int id) throws SQLException
    {
        this.repo.deleteById(id);
    }

    public Commodity getCommodityById(int id) throws SQLException
    {
        return this.repo.getById(id);
    }

    public List<Commodity> searchCommodity(String key) throws SQLException
    {
        return this.repo.search(key);
    }

    public void setRepo(CommodityRepo repo) {
        this.repo = repo;
    }

}
